package com.ruoyi.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mqtt.domain.bo.SysMqttBo;
import com.ruoyi.mqtt.service.ISysMqttService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 部门信息
 *
 * @author 曾午
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/mqtt")
public class SysMqttController extends BaseController {

    private final ISysMqttService mqttService;

    /**
     * 获取当前所有topic列表
     */
    @SaCheckPermission("system:mqtt:getTopics")
    @Log(title = "获取topic列表", businessType = BusinessType.OTHER)
    @GetMapping("/getTopics")
    public R<List<Map<String, Object>>> getTopics() {
        List<Map<String, Object>> topics = mqttService.getTopics();
        return R.ok(topics);
    }

    /**
     * 发送消息到指定topic
     */
    @SaCheckPermission("system:mqtt:sendMsgToTopic")
    @Log(title = "发送消息", businessType = BusinessType.OTHER)
    @PostMapping("/sendMsgToTopic")
    public void sendMsgToTopic(@RequestBody SysMqttBo mqttBo) {
        mqttService.sendMsgToTopic(mqttBo);
    }

    /**
     * 动态新增topic
     */
    @SaCheckPermission("system:mqtt:addTopic")
    @Log(title = "新增topic", businessType = BusinessType.OTHER)
    @PostMapping("/addTopic")
    public void addTopic(@RequestBody SysMqttBo mqttBo) {
        mqttService.addTopic(mqttBo);
    }

    /**
     * 动态移除topic
     */
    @SaCheckPermission("system:mqtt:removeTopic")
    @Log(title = "删除topic", businessType = BusinessType.OTHER)
    @PostMapping("/removeTopic")
    public void removeTopic(@RequestBody SysMqttBo mqttBo) {
        mqttService.removeTopic(mqttBo);
    }

}
